package wlf.controller;

import java.sql.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import wlf.pojo.Shop;
import wlf.pojo.Table;
import wlf.service.ShopService;

@Controller
public class ShopController {
	@Resource
	private ShopService shopServiceImpl;
	
	@ResponseBody
	@RequestMapping("/allShop")
	public List<Shop> allShop(){
		return shopServiceImpl.allShop();
	}
	@RequestMapping("/toUpdShop")
	public String toUpdSpu() {
		return "/WEB-INF/backstage/goods/updSpu.jsp";
	}

	@ResponseBody
	@RequestMapping("/shopPage")
	public Table<Shop> shopPage(int page, int limit, Shop shop) {
		Table<Shop> list = shopServiceImpl.page(page, limit, shop);
		return list;
	}
	
	
	@RequestMapping("/selShopById")
	public ModelAndView selSpuById(Shop shop,HttpServletRequest request,int mid){
		ModelAndView m = new ModelAndView("/toPage?flag=1&id="+mid);
		Table<Shop> table = shopServiceImpl.page(1,1,shop);
		List<Shop> list = table.getData();
		request.setAttribute("obj",list.size()>0&&list!=null?list.get(0):null);
		return m;
	}
	
	@RequestMapping("/toAddShop")
	public ModelAndView toAddSpu(HttpServletRequest request){
		ModelAndView m = new ModelAndView("/WEB-INF/backstage/goods/shop.jsp");
		request.setAttribute("url","addShop");
		return m;
	}
	
	
	@ResponseBody
	@RequestMapping("/addShop")
	public boolean addShop(Shop shop){
		shop.setCreateTime(new Date(System.currentTimeMillis()));
		int result = shopServiceImpl.addShop(shop);
		if(result>0){
			return true;
		}
		return false;
	}
	
	@ResponseBody
	@RequestMapping("/delShop")
	public boolean delSpu(int id){
		int result = shopServiceImpl.delShop(id);
		if(result>0){
			return true;
		}
		return false;
	}
	@ResponseBody
	@RequestMapping("/updShop")
	public boolean updShop(Shop shop){
		int result = shopServiceImpl.updShop(shop);
		if(result>0){
			return true;
		}
		return false;
	}
	
	@ResponseBody
	@RequestMapping("/updShopStatus")
	public boolean updShopStatus(int id,int status){
		int result = shopServiceImpl.updShopStatus(id,status);
		if(result>0){
			return true;
		}
		return false;
	}
	
	
	
}
